package sistema.web.servlet.servicio;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistema.web.bussiness.IServicioBussiness;
import sistema.web.bussiness.impls.ServicioBussiness;
import sistema.web.dtos.ServicioDTO;

/**
 * Servlet implementation class ServicioListar_Servlet
 */
@WebServlet("/ServicioListar_Servlet")
public class ServicioListar_Servlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServicioListar_Servlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		
		String nombre = request.getParameter("nombre");
		
		if(nombre != null && nombre.length() != 0) {
			IServicioBussiness bus = new ServicioBussiness();
			List<ServicioDTO> listServicio = bus.listar("Nombre", nombre);
		
			request.setAttribute("listServicio", listServicio);			
		} else {
			request.setAttribute("error", "Debe ingresar el nombre");
		}
		
		RequestDispatcher rd = request.getRequestDispatcher("/list_servicio.jsp");
        rd.forward(request, response);
	}
}